package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.badge.BadgeConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class BadgeConfigDaoImpl extends TempDao {
    private static String sql = "select * from `t_p_badge` ORDER BY `id` ASC";
    public List<BadgeConfig> getConfigList() {
        List<BadgeConfig> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                BadgeConfig config = new BadgeConfig();
                config.setId(rs.getInt("id"));
                config.setLevel((rs.getInt("level")));
                config.setType(rs.getInt("type"));
                config.setUnlockValue(rs.getLong("unlockValue"));
                config.setSkillsList(rs.getString("skillsList"));
                config.setSpecialEffect(rs.getString("specialEffect"));
                config.setExParam(rs.getString("exParam"));
                config.setSeasonParam(rs.getString("seasonParam"));
                list.add(config);
            }
            return list;
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return null;
    }

}
